package mobi.hami.huapin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import mobi.hami.huapin.base.Result;
import mobi.hami.huapin.constants.BaseEnums;
import mobi.hami.huapin.dto.PageDTO;
import mobi.hami.huapin.model.OpinionLeader;
import mobi.hami.huapin.model.Product;
import mobi.hami.huapin.model.base.PageVO;
import mobi.hami.huapin.service.OpinionLeaderService;
import mobi.hami.huapin.service.ProductService;
import mobi.hami.huapin.util.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/product/opinionleader", produces = "application/json")
@Api(description = "意见领袖api")
public class OpinionLeaderController {

    private final Logger logger = LoggerFactory.getLogger(OpinionLeaderController.class);

    @Autowired
    private OpinionLeaderService opinionLeaderService;

    @RequestMapping(value = "/add.do", method = RequestMethod.POST)
    @ApiOperation(value = "添加", notes = " ")
    public Result add(@RequestBody OpinionLeader opinionLeader) {

        opinionLeader.setDeleted(0);
        long rs = opinionLeaderService.save(opinionLeader);
        return Results.successWithData(rs, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }

    @RequestMapping(value = "/update.do", method = RequestMethod.POST)
    @ApiOperation(value = "更新", notes = " ")
    public Result update(@RequestBody OpinionLeader opinionLeader) {

        int rs = opinionLeaderService.update(opinionLeader);
        return Results.successWithData(rs, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());

    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除", notes = " ")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "id号", example = "abc", paramType = "query", required = true, dataType = "Long"),
            }
    )
    public Result productDelete(@RequestParam Long id) {

        return Results.successWithData(opinionLeaderService.delete(id), BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());

    }

    @RequestMapping(value = "/list.do", method = RequestMethod.POST)
    @ApiOperation(value = "获取列表", notes = "{\n" +
            "  \"pageindex\": \"1\",\n" +
            "  \"pagesize\": \"20\",\n" +
            "  \"order_name\": \"id\",\n" +
            "  \"order_type\": \"asc\"\n" +
            "}")
    public Result getList(@RequestBody Map<String, Object> reqMap)
    {
        logger.info("getList--》getlist");

        PageVO vo = opinionLeaderService.getList(reqMap);

        return Results.successWithData(vo, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }

}
